type TGet = {
  url: string;
  params: Record<string, string>;
};

export async function get({ url, params }: TGet) {
  try {
    const resp = await fetch(`${url}?${new URLSearchParams(params)}`, {
      method: 'GET',
    });
    const result = await resp.json();
    return result;
  } catch {
    return {
      error: 'GET_ERROR',
    };
  }
}

type TPost = {
  url: string;
  body: Record<string, string>;
};

export async function post({ url, body }: TPost) {
  try {
    const resp = await fetch(url, {
      method: 'POST',
      body: JSON.stringify(body),
    });
    const result = await resp.json();
    return result;
  } catch {
    return {
      error: 'POST_ERROR',
    };
  }
}
